package com.cucheng.chatroom.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cucheng.chatroom.dao.GroupInfoDao;
import com.cucheng.chatroom.dao.UserInfoDao;
import com.cucheng.chatroom.model.po.GroupInfo;
import com.cucheng.chatroom.model.po.UserInfo;
import com.cucheng.chatroom.service.GroupInfoService;

@Service
public class GroupInfoServiceImpl implements GroupInfoService {

    private static final Logger LOGGER = LoggerFactory.getLogger (GroupInfoServiceImpl.class);
    @Autowired
    private GroupInfoDao groupInfoDao;
    @Autowired
    private UserInfoDao  userInfoDao;

    /**
     *@Description: TODO(获取群和群列表成员) 
     *@Author: wangchengjie
     *@Since: 2019年3月30日下午3:35:26
     *@param groupId
     *@return
     */
    @Override
    public GroupInfo getByGroupId(String groupId){
        try {
            // 获取群
            GroupInfo groupInfo = groupInfoDao.selectByGroupId (groupId);
            // 拉取群成员
            List<UserInfo> members = userInfoDao.selectUserByGroupId (groupId);
            groupInfo.setMembers (members);
            return groupInfo;
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error (e.getMessage ());
        }
        return null;
    }

}
